package so.wy.servicecenter.businessbed.manager.fm;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.frame.manager.AbstractManager;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital.HospitalDAO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital.HospitalDO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_building.HospitalBuildingDAO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_building.HospitalBuildingDO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_depart.HospitalDepartDAO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_depart.HospitalDepartDO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_price.HospitalPriceDAO;
import so.wy.servicecenter.businessbed.dao.rdb.hospital.hospital_price.HospitalPriceDO;
import so.wy.servicecenter.data.dao.enums.YesNoEnum;

@Service
@Scope("prototype")
public class HospitalFManager extends AbstractManager {
    @Autowired
    private HospitalDAO hospitalDAO;

    @Autowired
    private HospitalBuildingDAO hospitalBuildingDAO;

    @Autowired
    private HospitalDepartDAO hospitalDepartDAO;

    @Autowired
    private HospitalPriceDAO priceDAO;

    //通过buildingId获取信息
    public HospitalBuildingDO getHospitalBuildingInfo(Long buildingId){
        if (buildingId == null){
            return null;
        }

        return hospitalBuildingDAO.selectById(buildingId);
    }

    //获取部门信息
    public HospitalDepartDO getHospitalDepart(Long departId){
        if (departId == null){
            return null;
        }

        return hospitalDepartDAO.selectById(departId);
    }

    //获取医院信息
    public HospitalDO getHospitalInfo(Long hospitalId){
        if (hospitalId == null){
            return null;
        }
        return hospitalDAO.selectById(hospitalId);
    }

    //校验医院是否可租赁
    public void checkRent(Long hospitalId){
        //校验当前时间段设备是否可租赁
    }



    //根据医院id获取定价信息
    public HospitalPriceDO getHospitalPriceInfo(Long hospitalId) {
        return priceDAO.selectOne(new LambdaQueryWrapper<HospitalPriceDO>()
                .eq(HospitalPriceDO::getHospitalId, hospitalId)
                .eq(HospitalPriceDO::getIsOpen, YesNoEnum.YES.getCode()));
    }


    //更新医院信息
    public void updateHospitalInfo(HospitalDO hospitalDO){
        hospitalDAO.updateById(hospitalDO);
    }
}
